<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var obj4 = {
        name: "王五",
        age: 17,
        fn1: function (a, b) {
          console.log(a+"+"+b+"=" + (a + b));
        },
        fn2: function () {
          console.log("我是对象里面的方法4");
        },
      };
      //对象引用
      console.log(obj4.name);
      obj4.fn1(1, 2);
      obj4.fn1("hello", "world");

      console.log(obj4["name"]); //这里的引号不能省略
      obj4["fn1(1, 2)"];
      obj4["fn1('hello', 'world')"];

      var str1 = "aa";
      var str2 = "bb";
      console.log(obj4[str1]); //当属性名为一个变量时，只能用[]去取值，且不能加引号，因为它是变量
      obj4.fn1(str1,str2);//参数可以为变量
    </script>
  </body>
</html>
